import asyncio
import time

from utils.handler import AsyncHandler, AsyncHandler2
from utils.log import Log


class MyClass(Log):
    @AsyncHandler2(end=True)
    def f(self, s, a, b=2):
        time.sleep(s)
        self.info(f'f({s}, {a}, {b}) done')
        # self.f1()
        return 42

    @AsyncHandler2(end=True)
    def f1(self, b=2):
        time.sleep(s)
        self.info(f'f1({b}) done')
        return 42

    @AsyncHandler2(end=True)
    async def g(self):
        await self.g1()
        await self.f(1, 2)
        self.info('g done')
        return 1
        # self.error(33, "test error")

    @AsyncHandler2(end=True)
    async def g1(self):
        self.info('g1 done')
        return 1


async def main():
    my_class = MyClass()
    return await asyncio.gather(my_class.f(3, 1), my_class.f(3, 1, 2),
                                my_class.f(3, 1, 2), my_class.f(3, 1, 2),
                                my_class.g())


if __name__ == '__main__':
    asyncio.run(main())
